<template>
  <div id="detail">
    <detail-nav-bar></detail-nav-bar>
    <scroll class="content" ref="scroll">
      <detail-swiper :topImages="topImages"/>
      <detail-base-info :goods="goods"/>
      <detail-shop-info :shop="shop"/>
      <detail-goods-info :detail-info="detailInfo" @imageLoad="imageLoad"/>
      <detail-param-info :param-info="paramInfo"/>
      <detail-comment-info/>
    </scroll>
  </div>
</template>

<script>
import DetailNavBar from "@/views/detail/childComps/DetailNavBar";
import DetailSwiper from "@/views/detail/childComps/DetailSwiper";
import DetailBaseInfo from "@/views/detail/childComps/DetailBaseInfo";
import DetailShopInfo from "@/views/detail/childComps/DetailShopInfo";
import DetailGoodsInfo from "@/views/detail/childComps/DetailGoodsInfo";
import DetailParamInfo from "@/views/detail/childComps/DetailParamInfo";
import DetailCommentInfo from "@/views/detail/childComps/DetailCommentInfo";

// 工具
import Scroll from "@/components/common/scroll/Scroll";
// 网络请求
import {getDetail, Goods, Shop, GoodsParam} from "@/network/detail";


export default {
  name: "Detail",
  components: {
    DetailCommentInfo,
    DetailParamInfo,
    Scroll,
    DetailShopInfo,
    DetailSwiper,
    DetailNavBar,
    DetailBaseInfo,
    DetailGoodsInfo
  },
  data() {
    return {
      iid: null,
      topImages: [],
      goods: {},
      shop: {},
      detailInfo: {}, // 详情
      paramInfo: {}, // 参数
      commentInfo: {} // 评论
    }
  },
  created() {
    // 1.保存插入的iid
    this.iid = this.$route.params.iid
    // 2.根据iid请求获取详情数据
    getDetail(this.iid).then(res => {
      const data = res.result
      // 1.获取顶部的图片轮博数据
      this.topImages = data.itemInfo.topImages
      // 2.获取商品信息
      this.goods = new Goods(data.itemInfo, data.columns, data.shopInfo.services)
      // 3.获取店铺信息
      this.shop = new Shop(data.shopInfo)
      // 4.保存商品详情的数据
      this.detailInfo = data.detailInfo
      // 5.获取参数信息
      this.paramInfo = new GoodsParam(data.itemParams.info,data.itemParams.rule)
      // 6.获取评论信息
      if(data.rate.cRate !== 0) {
        this.commentInfo == data.rate.list[0]
      }
    })
  },
  methods: {
    imageLoad() {
      return this.$refs.scroll.refresh()
    }
  }
}
</script>

<style scoped>
  #detail {
    position: relative;
    z-index: 9;
    background-color: #f6f6f6;
    height: 100vh;
  }
  .content {
    position: absolute;
    top: 44px;
    bottom: 49px;
    left: 0;
    right: 0;
    overflow: hidden;
  }
</style>